package com.gitee.ywj1352.common.util;

import com.gitee.ywj1352.common.message.RequestMessage;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.lang.reflect.Method;
import java.util.Map;

/**
 * Structured client clazz
 *
 * @author wenjieyang
 */
@Data
@NoArgsConstructor
public class ClientStructure {

    private String name;

    private Class<?> clientClazz;

    private String targetServerName;

    private Map<String, MethodStructure> methodsMap;

    @Data
    public static class MethodStructure {

        private String name;

        private Method method;

        private Class<?> returnClazz;

        private Class<?>[] paramsType;

        public MethodStructure() {
        }
    }

    /**
     * generateRequestMessage
     * @param name
     * @param params
     * @return
     */
    public RequestMessage generateRequestMessage(String name, Object[] params) {
        MethodStructure methodStructure = this.methodsMap.get(name);
        return new RequestMessage(IdUtil.nextId(), methodStructure.getParamsType(), params);
    }


}
